require 'c:/tools/kronos/ruby/line'
require 'c:/tools/kronos/ruby/state'
require 'c:/tools/kronos/ruby/merge'
require 'c:/tools/kronos/ruby/pseudostate'
require 'c:/tools/kronos/ruby/formalstate'

class FSM

  attr_accessor :lines
  attr_accessor :states
  attr_accessor :merges
  attr_accessor :pseudo_states
  attr_accessor :formal_states

  def initialize( xml_doc )

    @xml_doc = xml_doc

    @lines         = Array.new
    @states        = Array.new
    @merges        = Array.new

		# At this time, the only pseudostate that can
		# exist, is the initial system state.
    @pseudo_states  = Array.new

    loadFSM

    @lines.each { |line|
      line.consolidateLineNames @states
    }

    @pseudo_states.each { |pseudo|
      pseudo.consolidatePseudostateNames @states
    }

    @formal_states = FormalStateController.new @lines

		# Print Final Documents

		# Debug Printing
		# @formal_states.printStates
		# @formal_states.printMerge

  end

  def loadFSM

		# Filter out "Master's"of interest, and load 
		# the appropriate array with the correct information

    @xml_doc.elements.each { |element|

      case element.attributes["Master"]
        when "0"  # State
          @states.push State.new element
        when "2"  # Line to Decision/ Merge
          @lines.push Line.new element
        when "5"  # Pseudo State
          @pseudo_states.push PseudoState.new element
        when "8"  # Decision/ Merge
          @merges.push Merge.new element
        when "11" # Line
          @lines.push Line.new element
      end

    }

  end

	def loadAnotherFSMPage

	end

end
